﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SchEdu.Framework.DataModel;

namespace SchEduApp
{
    public partial class SolutionForm : Form
    {
        public SolutionForm()
        {
            InitializeComponent();
            solutionBindingSource.DataSource = SchEduAppContext.SchEduData.SchEduDataSet;
        }

        private void aboutAlgorithmButton_Click(object sender, EventArgs e)
        {
            DataGridViewRow dgvr = solutionDataGridView.CurrentRow;
            if (dgvr == null)
            {
                return;
            }
            DataRowView drv = dgvr.DataBoundItem as DataRowView;
            if (drv == null)
            {
                return;
            }

            SchEduDataSet.SolutionRow solution = drv.Row as SchEduDataSet.SolutionRow;
            if (solution == null)
            {
                return;
            }

            AboutForm aboutForm = new AboutForm();
            AboutInfo aboutInfo = new AboutInfo();
            aboutInfo.Title = solution.Title;
            aboutInfo.Company = solution.Company;
            aboutInfo.Copyright = solution.Copyright;
            aboutInfo.Description = solution.Description;
            aboutInfo.Product = solution.Product;
            aboutInfo.Version = solution.Version;
            aboutForm.SetAboutInfo(aboutInfo);
            aboutForm.ShowDialog();

        }

        private void objectiveAlgorithmButton_Click(object sender, EventArgs e)
        {
            DataGridViewRow dgvr = objectiveDataGridView.CurrentRow;
            if (dgvr == null)
            {
                return;
            }
            DataRowView drv = dgvr.DataBoundItem as DataRowView;
            if (drv == null)
            {
                return;
            }

            SchEduDataSet.PerformanceRow performance = drv.Row as SchEduDataSet.PerformanceRow;
            if (performance == null)
            {
                return;
            }

            AboutForm aboutForm = new AboutForm();
            AboutInfo aboutInfo = new AboutInfo();
            aboutInfo.Title = performance.Title;
            aboutInfo.Company = performance.Company;
            aboutInfo.Copyright = performance.Copyright;
            aboutInfo.Description = performance.Description;
            aboutInfo.Product = performance.Product;
            aboutInfo.Version = performance.Version;
            aboutForm.SetAboutInfo(aboutInfo);
            aboutForm.ShowDialog();

        }

        private void ganttToolStripButton_Click(object sender, EventArgs e)
        {
            DataGridViewRow dgvr = solutionDataGridView.CurrentRow;
            if (dgvr == null)
            {
                return;
            }
            DataRowView drv = dgvr.DataBoundItem as DataRowView;
            if (drv == null)
            {
                return;
            }

            SchEduDataSet.SolutionRow solution = drv.Row as SchEduDataSet.SolutionRow;
            if (solution == null)
            {
                return;
            }

            GanttForm ganttForm = new GanttForm();
            ganttForm.Solution = solution;
            ganttForm.MdiParent = this.MdiParent;
            ganttForm.Show();
        }

        private void compareToolStripButton_Click(object sender, EventArgs e)
        {
            SolutionList solutions;
            DataGridViewSelectedRowCollection dgvsrc = solutionDataGridView.SelectedRows;
            if (dgvsrc.Count == 0)
            {
                solutions = new SolutionList(SchEduAppContext.SchEduData.Solution);
              
            }
            else
            {
                solutions = new SolutionList();
                foreach (DataGridViewRow dgvr in dgvsrc)
                {
                    DataRowView drv = dgvr.DataBoundItem as DataRowView;
                    if (drv == null)
                    {
                        continue;
                    }

                    SchEduDataSet.SolutionRow solution = drv.Row as SchEduDataSet.SolutionRow;
                    if (solution == null)
                    {
                        continue;
                    }
                    solutions.Add(solution);
                }
            }
            if (solutions.Count == 0)
            {
                return;
            }
            ComparisonForm compareForm = new ComparisonForm();
            compareForm.Solutions = solutions;
            compareForm.MdiParent = this.MdiParent;
            compareForm.Show();

        }
    }
}
